package com.ykq.controller;

import com.ykq.pojo.User;
import com.ykq.service.UserService;
import com.ykq.vo.LoginVo;
import com.ykq.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @program: vue_axios_ssm
 * @description:
 * @author: 闫克起2
 * @create: 2023-05-18 10:00
 **/
@Controller
public class LoginController {

    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    @ResponseBody
    public Result login(@RequestBody LoginVo loginVo, HttpSession session){
        User user = userService.selectByNameAndPassword(loginVo);
        if(user!=null){
             //用户信息保存到session会话中
            session.setAttribute("user",user);
            return new Result(200,"登录成功",null);
        }else{
            return new Result(500,"账号或密码错误",null);
        }
    }
}










